﻿using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace TxtManager.WPF.ViewModels;

public partial class CreateItemDialogViewModel : ObservableValidator
{
    [Required(ErrorMessage = "标题不能为空")]
    [MinLength(2, ErrorMessage = "标题至少需要2个字符")]
    [MaxLength(100, ErrorMessage = "标题不能超过100个字符")]
    [ObservableProperty]
    private string _title = string.Empty;

    [ObservableProperty]
    [MaxLength(500)]
    private string _textDescription = string.Empty;

    [ObservableProperty]
    [MaxLength(50)]
    private string _tag = "未分类";
    
    public bool Validate()
    {
        ValidateAllProperties();
        return !HasErrors;
    }
}